﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using FRL.DebtChased.Repository;

namespace FRL.DebtChased.Website
{

	/// <summary>
	/// Declaration of MyApplication class
	/// </summary>
	public class MyApplication
	{

		/////////////////////////////////////////////////////////////////
		// Constants

		private const String keyName = "_appKey";

		/////////////////////////////////////////////////////////////////
		// Attributes

		private int m_iSessionTimeoutMins = 20;
		public int SessionTimeoutMins
		{
			get { return m_iSessionTimeoutMins; }
		}

		private string m_strFinancialName;
		public string FinancialName
		{
			get { return m_strFinancialName; }
		}

		private string m_strLocationCountryCode = "UK";
		public string LocationCountryCode
		{
			get { return m_strLocationCountryCode; }
		}

		private bool m_bCreditCardPaymentEnabled = false;
		public bool CreditCardPaymentEnabled 
		{ 
			get { return m_bCreditCardPaymentEnabled; } 
		}

		private System.Drawing.Color m_colPrimaryWebColor = System.Drawing.Color.Black;
		public System.Drawing.Color PrimaryWebColor
		{
			get { return m_colPrimaryWebColor; }
		}

		private System.Drawing.Color m_colSecondaryWebColor = System.Drawing.Color.White;
		public System.Drawing.Color SecondaryWebColor
		{
			get { return m_colSecondaryWebColor; }
		}

		/////////////////////////////////////////////////////////////
		// Construction

		private MyApplication()
		{

			// Initialize member variables

		}

		/////////////////////////////////////////////////////////////
		// Operations

		public void Refresh()
		{

			// Open data repository
			using (DebtChasedEntities ent = new DebtChasedEntities())
			{

				// Get the configuration settings
				//SystemConfig sc = ent.SystemConfigs.First();
				//if (sc != null)
				{

                    //// Retain system configuration values
                    //m_iSessionTimeoutMins = sc.SessionTimeoutMins;
                    //m_strFinancialName = sc.FinancialName;

                    //int iColor = sc.PrimaryWebColor;
                    //m_colPrimaryWebColor = Color.FromArgb((iColor>>24) & 0xFF,(iColor>>16) & 0xFF,(iColor & 0xFF));

                    //iColor = sc.SecondaryWebColor;
                    //m_colSecondaryWebColor = Color.FromArgb((iColor >> 24) & 0xFF, (iColor >> 16) & 0xFF, (iColor & 0xFF));

				}

			}

		}

		/////////////////////////////////////////////////////////////
		// Static Operations

		public static MyApplication BindMyApplication()
		{

			// Get the session variable
			MyApplication Ftmp = HttpContext.Current.Application[keyName] as MyApplication;
			System.Diagnostics.Trace.Assert(Ftmp != null);

			// Return variable
			return Ftmp;

		}

		public static void Startup()
		{

			// Create a new application object
			MyApplication Ftmp = new MyApplication();

			// Binding to the application context	
			HttpContext.Current.Application[keyName] = Ftmp;

			// Update the member variables
			Ftmp.Refresh();

		}

	}

}